// Start with closed cases and get closing method, closing date and case_type

clear
set more off

use "${raw}/nlrb/R_CLOSED_CASE.dta",clear
drop date_file_to_records date_file_destroyed date_file_archives
duplicates drop _all,force

g year=year(closing_date)
g month=month(closing_date)

drop if year==1999 & month<=9
drop if year==2010 & month>=6
drop if year<1999 | year>2010

drop year month

g case_type=substr(r_case_number,4,2)
keep if inlist(case_type,"RC","RD","RM")

duplicates drop r_case_number case_type closing_date closing_method,force

* Keep most recent closing_date
bys r_case_number: egen recent=max(closing_date)
format recent %td
keep if closing_date==recent

* Remaining Issues
duplicates tag r_case_number,g(dups)
sort dups r_case_number

drop if closing_method==. & dups>0

drop dups
duplicates tag r_case_number,g(dups)
sort dups r_case_number

// Going to have to drop duplicates as there is no way to determine the outcome
// No way to determine which  sequence came first
// Alos not possible to use the online Case Search tool (no idea on reliability either)
drop if dups!=0

keep r_case_number closing_date closing_method case_type

save "${temp}/closed_cases_clean.dta",replace
